<!DOCTYPE html>
<html class="page">

<head>
    <title>邀请好友</title>
    <meta charset="utf-8">
    <meta name="keywords" content="气派 " />
    <script src="https://ami-static.b0.upaiyun.com/active2016/base/flexible.js"></script>

    <link rel="stylesheet" href="static/style/index.scss" />

</head>

<body class="page-3 page-4">
    <img src="./static/imgs/5-1.jpg" />
    <div class="intro">
        <p>
            亲！
            <br /> 送你
            <span>188</span>元竞优理财现金红包赶紧领取吧！
        </p>
        <div id="fInfo">
            你的好友
            <br />
            <label>* 好雨 135****8832</label>
        </div>
    </div>
    <div class="form-box">
        <div class="f-input">
            <input type="text" id="tel" placeholder="请输入您的手机号" maxlength="11" class="input" />
        </div>
        <div id="btn" class="f-btn select">接受邀请</div>
    </div>

    <!-- 脚本 -->
    <script src="static/script/lib/jquery.js"></script>
    <script>
        var modal = {
            show: function (txt) {
                $("body").append(
                    "<div class='modal'><div class='m-mask'></div><div class='m-inner'><div class='m-txt'>" +
                    txt + "</div><div id='mBtn' class='m-btn'>确定</div></div></div>");

                var self = this;
                var $btn = document.getElementById("mBtn");
                $btn.addEventListener("click", self.hide, false);
            },
            hide: function () {
                $("body").find(".modal").remove();
            }
        };

        // 获取地址栏里面的参数
        var getLocationParams = function (name) {
            // 获取地址栏参数
            var
                href = window.location.href,
                subIndex = href.indexOf("?"),
                paramsObj = {};
            if (subIndex != -1) {
                var params = href.substr(subIndex + 1);
                var paramsMany = params.indexOf("&");
                if (paramsMany != -1) {
                    var paramsArr = params.split("&");
                    paramsArr.forEach((item, index) => {
                        paramsObj[item.split("=")[0]] = item.split("=")[1];
                    })
                } else {
                    paramsObj[params.split("=")[0]] = params.split("=")[1];
                }
            }

            if (paramsObj.hasOwnProperty(name)) {
                return paramsObj[name];
            } else {
                return null
            }
        }



        var fName = decodeURI(getLocationParams("friendName"));
        var fMobile = getLocationParams("friendCell");
        var fCode = getLocationParams("inviteCode");

        var $tel = $("#tel"),
            $btn = $("#btn"),
            btnFlag = false,
            $val;

        if (fName != null && fName != null && fCode != null) {
            $("#fInfo").find("label").html(fName + "　" + fMobile);

            $btn.on("click", function () {
                if ($tel.val().length == 11) {
                    $.ajax({
                        url: "http://www.chutengkeji.com:8080/financingrest/investSubmit.do",
                        type: "GET",
                        data: {
                            inviteCell: $tel.val(),
                            inviteCode: fCode
                        },
                        success: function (res) {
                            if (res.success) {
                                modal.show("操作成功");
                            }
                        },
                        error: function () {

                            modal.show("服务器开小差了");
                        }
                    })
                } else {
                    modal.show("请输入正确的手机号");
                }
            })

        } else {
            modal.show("地址栏参数错误");
        }



        //
    </script>
</body>

</html>